//不断移动的陆地
import Sprite from '../base/Sprite.js'
import DataStore from '../base/DataStore.js'
import Director from '../Director.js'

export default class extends Sprite {
  constructor() {
    const img = DataStore.getInstance().res.get('land')
    super(
      img,
      0, 0,
      img.width, img.height,
      0, DataStore.getInstance().canvas.height - img.height,
      img.width, img.height
    )
    this.landX = 0
    this.landSpeed = Director.getInstance().moveSpeed
    this.xMax = Math.abs(DataStore.getInstance().canvas.width - img.width)
  }
  draw(
    img = this.img, srcX = this.srcX, srcY = this.srcY, srcW = this.srcW,
    srcH = this.srcH, x = this.x, y = this.y, width = this.width,
    height = this.height) {
    this.landX = this.landX - this.landSpeed
    if (Math.abs(this.landX) >= this.xMax ) {
      this.landX = 0
    }
    super.draw(img, srcX, srcY, srcW, srcH, this.landX, y, width, height)
  }
}
